<?php
/**
 * Created by PhpStorm.
 * User: lphwxl
 * Date: 2018/7/11
 * Time: 13:37
 */

namespace App\Http\Controllers\Api\V1;


use App\Http\Controllers\Controller;
use Firebase\JWT\JWT;
use function foo\func;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use App\Model\Order as OrderModel;
use Illuminate\Support\Facades\DB;

class Order extends Controller
{

    /**
     * Notes: 我的订单
     * User: lphwxl
     * @param Request $request
     * @return JsonResponse
     */

    public function orderList(Request $request){



        $page = $request->input('page',10);

        //$res = JWT::encode(['user_id'=>1],'xzg_zhs','HS256');


        $order = OrderModel::with(['tasks'=>function($query){

                        $query->with(['imageList'=>function($query){
                            $query->select('id','href','task_id');
                        }])->select('id','title','shop_name','money','goods_name','task_number');
                    }])->where('user_id',$request->user_id)
                    ->where('status',$request->status)
                    ->paginate($page);


        return JsonResponse::create([
            'code'=>200,
            'msg'=>'ok',
            'data'=>$order->toArray()
        ]);

    }


    /**
     * Notes: 单图片上传
     * User: lphwxl
     * @param Request $request
     * @return JsonResponse
     */
    public function upload(Request $request){
        //TODO
        return JsonResponse::create([
            'code'=>200,
            'msg'=>'ok',
            'data'=>[
                //图片路径
            ]
        ]);
    }






}